package com.example.demo.study.thread;

public class JoinTry {
    public static int num=0;
    public static Object lock=new Object();
    public static void add()
    {
        num=num+1;
    }
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            for(int i=1;i<=50000000;i++)
            {
                synchronized (lock)
                {
                    add();
                }
            }

        });
        Thread t2=new Thread(()->{
            for(int i=50000001;i<=100000000;i++)
            {
                synchronized (lock)
                {
                    add();
                }
            }

        });
        t1.start();
        t2.start();
//        t1.join();
//        t2.join();
        System.out.println("汇总结果： "+num);
    }
}
